package com.itheima.app.controller;

import com.itheima.app.manager.MakeFriendManager;
import com.itheima.domain.db.Answers;
import com.itheima.domain.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 交友模块
 */
@RestController
public class MakeFriendController {

    @Autowired
    private MakeFriendManager makeFriendManager;

    /**
     * 今日佳人
     * @return
     */
    @GetMapping("/tanhua/todayBest")
    public RecommendUserVo todayBest(){
        return makeFriendManager.todayBest();
    }


    /**
     *  推荐列表
     * @param page
     * @param pageSize
     * @return
     * @throws IOException
     */
    @GetMapping("/tanhua/recommendation")
    public PageBeanVo findRecommdUserList(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) throws IOException {


        return  makeFriendManager.findRecommendUserList(page ,pageSize );
    }


    /**
     * 查询推荐用户详情信息
     */
    @GetMapping("/tanhua/{recommendUserId}/personalInfo")
    public RecommendUserVo findRecommendUserById(
            @PathVariable Long recommendUserId
    ) throws IOException {


        return  makeFriendManager.findRecommendUserById(recommendUserId);
    }
    /**
     * 查询推荐用户详情信息
     */
    @GetMapping("/tanhua/strangerQuestions")
    public String findQuestionByUserId(
            Long userId
    ) throws IOException {


        return  makeFriendManager.findQuestionByUserId(userId);
    }
    /**
     * 查看最近访客
     */
    @GetMapping("/movements/visitors")
    public List<VisitorVo> findVisitors() throws IOException {


        return  makeFriendManager.findVisitors();
    }

    /**
     * 查看附近的人
     */
    @GetMapping("/tanhua/search")
    public List<NearUserVo> findNearUser(String gender , String distance) throws IOException {
        return  makeFriendManager.findNearUser(gender , distance);
    }


    /**
     * 发送陌生人消息
     */
    @PostMapping("/tanhua/strangerQuestions")
    public Map sendHuanxinMsg(@RequestBody Map map) throws IOException {
        String userId = map.get("userId").toString();
        String reply = map.get("reply").toString();
        makeFriendManager.sendHuanxinMsg(userId , reply);
        return null;
    }
    /**
     * 联系人添加
     */
    @PostMapping("/messages/contacts")
    public Map addContacts(@RequestBody Map map) throws IOException {
        //friendId
        String friendId = map.get("userId").toString();
        makeFriendManager.addContacts(friendId);
        return null;
    }



    /**
     * 联系人列表
     */
    @GetMapping("/messages/contacts")
    public PageBeanVo findContactList(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) throws IOException {


        return   makeFriendManager.findContactList(page , pageSize);
    }



    /**
     * 探花卡片
     */
    @GetMapping("/tanhua/cards")
    public List findCards() throws IOException {
        //只查询20张卡片即可
        PageBeanVo pageBeanVo = makeFriendManager.findRecommendUserList(1, 20);
        List list = pageBeanVo.getItems();
        return list;
    }



    //测灵魂-问卷列表
    @GetMapping("/testSoul")
    public List<QuestionnaireVo> findTestSoul() {
        return makeFriendManager.findTestSoul();
    }

    //测灵魂-提交
    @PostMapping("/testSoul")
    public String saveTestSoul(@RequestBody Map<String, List<Answers>> answers) {
        List<Answers> answers1 = answers.get("answers");
        return makeFriendManager.saveTestSoul(answers1);
    }

    //测灵魂-查看
    @GetMapping("/testSoul/report/{id}")
    public TestResultVo findResult(@PathVariable("id") Long id) {
        return makeFriendManager.findResult(id);
    }


    /**
     * 桃花传音---接收语音：
     * @throws IOException
     */
    @GetMapping("/peachblossom")
    public SoundVo receiveVoice() throws IOException {

        return makeFriendManager.receiveVoice();
    }


    /**
     * 桃花传音---发送语音：
     * @throws IOException
     */
    @PostMapping("/peachblossom")
    public void saveVoice(MultipartFile soundFile) throws IOException {

        makeFriendManager.saveVoice(soundFile);
    }
}
